<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * @author xiaoting <[<yichen.ye@zhaopin.com.cn>]>
 * @date(2017.9.18)
 *
 * 功能业务接口
 */

class Feauitinterface_xiaoting extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('comon_model');
		$this->load->model('groupusers_model');
		$this->load->model('wafrules_model');
		$this->load->model('waf_model');
		$this->load->model('order_model');
		$this->load->model('user_model');
		// $this->load->helper('url');
		// $this->load->library('session');
	}

	/**
	 * 默认路由
	 * @return [type] [description]
	 */
	function index()
	{
		echo json_encode(array('status' => 0));
	}

	/**
	 * 核心路由
	 * @return [type] [description]
	 */
	function worker_routes()
	{
		// 方法选择
		$jump = $this->input->get_post('jump',TRUE);

		switch ($jump) {

			case 'behinds':
				if($this->comon_model->_userpower("0404000") < 0)
					die('{"status":-600}');
				$this->behinds($this->input);
				break;

			case 'users':
				if($this->comon_model->_userpower("0701000") < 0) 
					die('{"status":-600}');
				$this->users($this->input);
				break;

			case 'power':
				if($this->comon_model->_userpower("0703000") < 0) 
					die('{"status":-600}');
				$this->power($this->input);
				break;

			case 'groupusers':
				if($this->comon_model->_userpower("0702000") < 0) 
					die('{"status":-600}');
				$this->groupusers($this->input);
				break;
			case 'frame':
				$this->frame($this->input);
				break;

			case 'src':
				if($this->comon_model->_userpower("0704000") < 0) 
					die('{"status":-600}');
				$this->src($this->input);
				break;

			case 'wafrule':
				if($this->comon_model->_userpower("0601000") < 0) 
					die('{"status":-600}');
				$this->wafrule($this->input);
				break;

			case 'waf':
				if($this->comon_model->_userpower("0201000") < 0) 
					die('{"status":-600}');
				$this->waf($this->input);
				break;

			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}

	/**
	 * 滞后事件的处理
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function behinds($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			// 添加滞后事件
			case 'add':
				echo json_encode($this->order_model->behind_add($commonds));
				break;

			// 添加的tab事件
			// 获取用户列表
			case 'addclick':
				echo json_encode($this->user_model->users_select());
				break;

			// 删除滞后事件
			case 'delete':
				echo json_encode($this->order_model->behind_delete($commonds));
				break;

			// 滞后事件的列表
			case 'list':
				echo json_encode($this->order_model->behind_list($commonds));
				break;
			
			// 读取单个滞后事件
			case 'read':
				echo json_encode($this->order_model->behind_read($commonds));
				break;

			// 修改单个滞后事件
			case 'change':
				echo json_encode($this->order_model->behind_change($commonds));
				break;

			// 确认修改单个滞后事件
			case 'surechange':
				echo json_encode($this->order_model->behind_surechange($commonds));
				break;

			// 推进单个滞后事件
			case 'push':
				echo json_encode($this->order_model->behind_push($commonds));
				break;

			// 确认推进单个滞后事件
			case 'surepush':
				echo json_encode($this->order_model->behind_surepush($commonds));
				break;

			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}

	/**
	 * 用户组的处理
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function groupusers($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			
			case 'add':
				if($this->comon_model->_userpower("0702001") < 0) 
					die('{"status":-600}');
				echo json_encode($this->groupusers_model->groupusers_add($commonds));
				break;

			case 'list':
				echo json_encode($this->groupusers_model->groupusers_list($commonds));
				break;

			case 'addlist':
				echo json_encode($this->groupusers_model->groupusers_addlist($commonds));
				break;

			case 'change':
				echo json_encode($this->groupusers_model->groupusers_change($commonds));
				break;//surechange

			case 'surechange':
				echo json_encode($this->groupusers_model->groupusers_surechange($commonds));
				break;

			case 'read':
				echo json_encode($this->groupusers_model->groupusers_read($commonds));
				break;
			
			case 'delete':
				echo json_encode($this->groupusers_model->groupusers_delete($commonds));
				break;

			default:
				echo json_encode(array('status' => 0));
				break;
		}
	}


	/**
	 * WAF防护规则的处理
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function wafrule($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			
			case 'add':
				// if($this->comon_model->_userpower("0401001") < 0) 
				// 	die('{"status":-600}');
				echo json_encode($this->wafrules_model->wafrule_add($commonds));
				break;

			case 'list':
				echo json_encode($this->wafrules_model->wafrule_list($commonds));
				break;

			// case 'addlist':
			// 	echo json_encode($this->wafrules_model->groupusers_addlist($commonds));
			// 	break;

			// case 'change':
			// 	echo json_encode($this->wafrules_model->wafrule_change($commonds));
			// 	break;//surechange

			// case 'surechange':
			// 	echo json_encode($this->wafrules_model->groupusers_surechange($commonds));
			// 	break;

			// case 'read':
			// 	echo json_encode($this->wafrules_model->groupusers_read($commonds));
			// 	break;
			
			// case 'delete':
			// 	echo json_encode($this->wafrules_model->groupusers_delete($commonds));
			// 	break;

			default:
				echo json_encode(array('status' => -10));
				break;
		}
	}

	/**
	 * WAF的处理
	 * @param  [type] $inputs [description]
	 * @return [type]         [description]
	 */
	private function waf($inputs)
	{
		$commonds = $inputs->post();

		switch ($commonds['commonds']) {

			
			case 'add':
				// if($this->comon_model->_userpower("0401001") < 0) 
				// 	die('{"status":-600}');
				echo json_encode($this->waf_model->waf_add($commonds));
				break;

			case 'listrules':
				echo json_encode($this->waf_model->waf_listrules($commonds));
				break;

			// case 'addlist':
			// 	echo json_encode($this->wafrules_model->groupusers_addlist($commonds));
			// 	break;

			// case 'change':
			// 	echo json_encode($this->wafrules_model->wafrule_change($commonds));
			// 	break;//surechange

			// case 'surechange':
			// 	echo json_encode($this->wafrules_model->groupusers_surechange($commonds));
			// 	break;

			// case 'read':
			// 	echo json_encode($this->wafrules_model->groupusers_read($commonds));
			// 	break;
			
			// case 'delete':
			// 	echo json_encode($this->wafrules_model->groupusers_delete($commonds));
			// 	break;

			default:
				echo json_encode(array('status' => -10));
				break;
		}
	}
}